<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    let p1 = new Promise((resolve, reject) => {
      // 状态改变后是不可逆的
      // resolve('成功')
      // reject('失败')
      setTimeout(()=>{
        reject('失败')
      }, 2000)
    })
    // then 是对上一个promise状态改变的处理, 每一个then返回的都是一个promise

    new Promise((resolve, reject) => {
      // reject(p1)
      resolve(p1)
    })
    
    let p2 = p1.then(msg => {
      console.log(msg)
    }, error => {
      console.log('error:' + error) // 
    }).then(null, reason => {
      console.log(reason)
    })

    console.log(p2)
  </script>
</body>
</html>